package com.itheima.collectiondemo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * @Author 王加鑫
 * @Date 2021/5/13 10:17
 * @Version 1.0
 * 迭代器
 */
public class IteratorDemo01 {
    public static void main(String[] args) {
        Collection<String> collection = new ArrayList<>();
        //往集合中添加3个人名
        collection.add("龟田大郎");
        collection.add("龟田次郎");
        collection.add("龟田太郎");

        for (String s:collection){
            System.out.println(s);
        }

        System.out.println("----------------------------");

        //迭代器对象用完一次过后会指向集合的底层不能再用了
        Iterator<String> iterator = collection.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }


    }
}
